package com.wjm.data_handle.event;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.ContextStartedEvent;
import org.springframework.stereotype.Component;

import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

@Component
public class ApplicationStartedListener implements ApplicationListener<ContextRefreshedEvent> {
    @Value("${server.port}")
    public String port;


    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
//        System.out.println("程序启动成功,请访问链接: http://localhost:"+port );
        System.out.println("程序启动成功...");
        Desktop desktop = Desktop.getDesktop();
        if (Desktop.isDesktopSupported() && desktop.isSupported(Desktop.Action.BROWSE)) {

            URI uri = null;
            try {
                uri = new URI("http://localhost:"+port);
            } catch (URISyntaxException e) {
                e.printStackTrace( );
            }
            try {
                desktop.browse(uri);
            } catch (IOException e) {
                e.printStackTrace( );
            }
        }

    }
}
